﻿// CallWebServiceMethods.js

// This function calls the Web service method without 
// passing the callback function. 
function GetNoReturn()
{
    Samples.AspNet.WebService.GetServerTime();
    alert("This method does not return a value.");
    
}


// This function calls the Web service method and 
// passes the event callback function.  
function GetTime()
{
    Samples.AspNet.WebService.GetServerTime(
    SucceededCallback);

}

 
function GetNewsId(id, userid) {
    Samples.AspNet.WebService.GetnewId(id,userid,
    SucceededCallback);

}

function checkUserName(id) {
    Samples.AspNet.WebService.checkUserName(id,SucceededCallbackUsername);

}


function zipcode(id) {
    Samples.AspNet.WebService.zipcode(id, SucceededCallback2);

}



function pritePage(currentpage) {
//alert(currentpage);
    Samples.AspNet.WebService.pritePage(currentpage, SucceededCallback);

}

function removeItem(currentpage) {
//alert(currentpage);
    Samples.AspNet.WebService.removeItem(currentpage);

}
// Thêm cart: 
function AddProduct(currentpage) {

   
    Samples.AspNet.WebService.AddCurrentCarr1(currentpage,showProduct);
    
    }

function getCurrentCart() {

var p ;
 // xóa các dùng đi
 
    
    Samples.AspNet.WebService.AddCurrentCarr1(0,showProduct);
    
    }

function updateItem(id,sl) {
   //alert('ID = ' + id + ' SL = ' + sl);
    Samples.AspNet.WebService.UpdateItem(id,sl);
    getCurrentCart();
    
   }



function searchNumber(id, userid) {
    
    Samples.AspNet.WebService.searchNumber(id.value, userid,
    SucceededCallback);

}

function DeleteCommete(id) {
    Samples.AspNet.WebService.DeleteCommete(id,
    SucceededCallback);

}

function DeleteCommete1(id, checkbox) {
    //alert(document.getElementById(checkbox).value);
    if (document.getElementById(checkbox).value == 0) {
        Samples.AspNet.WebService.DeleteCommete1(id, 1, SucceededCallback);
    } else {
    Samples.AspNet.WebService.DeleteCommete1(id, 0, SucceededCallback);
    }
    }

    function DeleteCommete2(id, checkbox) {
        var r = confirm("Ban có chắc chắn muốn xóa");
        if (r == true) {
           // alert("You pressed OK!");
            Samples.AspNet.WebService.DeleteCommete2(id, 1, SucceededCallback);
        }
        else {
         //   alert("You pressed Cancel!");
        }
        //alert(document.getElementById(checkbox).value);
       
           
        
    }



// This function calls the Web service method 
// passing simple type parameters and the 
// callback function  
function Add(a,  b)
{
    Samples.AspNet.WebService.Add(a, b, 
    SucceededCallback);
}

// This function calls the Web service method 
// that returns an XmlDocument type.  
function GetXmlDocument() 
{
    Samples.AspNet.WebService.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest() 
{

    Samples.AspNet.WebService.EchoStringAndDate(
        new Date("1/1/2007"), " Happy",
        SucceededCallback, 
        FailedCallback, "HappyNewYear");

}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;
    
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    
    var readResult;
    if (userContext == "XmlDocument")
	{
	
	    if (document.all) 
	        readResult = 
		        result.documentElement.firstChild.text;
		else
		    // Firefox
		   readResult =
		        result.documentElement.firstChild.textContent;
		
	     RsltElem.innerHTML = "XmlDocument content: " + readResult;
	}
    
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML = result;
}

function SucceededCallbackUsername(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("checkusername");
    RsltElem.innerHTML = result;
}



function printCart(result, eventArgs)
{
//alert(result);
     var items=result.split(',');
     var len=items.length;
        for(var i=0;i<len;i++)
           {
                if(items[i] !='0')
                    {
                        Samples.AspNet.WebService.getItem(items[i],addRow2);
                    }
           }
}

function getdata(result, eventArgs)
{
    // Page element to display feedback.
    return result;
}

function SucceededCallback1(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("Span1");
    RsltElem.innerHTML = result;
}

function showProduct(result, eventArgs) {
    // Page element to display feedback.
    var RsltElem = document.getElementById("productList2");
    RsltElem.innerHTML = result;
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}
 function addRow2(dataArr,eventArgs){
        var str = dataArr;
        var n=str.split(',');
                var tr=document.createElement('tr');
                var len=n.length;
                for(var i=0;i<3;i++){
                    var td=document.createElement('td');
                    td.appendChild(document.createTextNode(n[i]));
                    tr.appendChild(td);
                }
                 var td=document.createElement('td');
                 var td1=document.createElement('td');
    
                  var element1 = document.createElement('input');
            element1.name = 'SL';
           element1.onclick = "deleteRow1(" + len + ")";
            element1.setAttribute('type', 'input');
            element1.setAttribute('size', '3');
        	element1.setAttribute('value', n[3]);
	   td1.appendChild(element1);
            var element2 = document.createElement('input');
            element2.name = 'image';
            element2.onclick = "deleteRow1(" + len + ")";
            element2.setAttribute('type', 'button');
	element2.setAttribute('value', 'Xóa');
	element2.setAttribute('onclick', 'deleteRow1(this.parentNode.parentNode.rowIndex);');
            
            
            td.appendChild(element2);
                    tr.appendChild(td1);
                    tr.appendChild(td);
                 
                document.getElementById('productlists').appendChild(tr);
            }
            
            
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
